//
//  VideosViewController.m
//  糗事-1
//
//  Created by 龚骏翔 on 15/3/25.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "VideosViewController.h"
//#import "VideoTableViewCell.h"
//#import "AFHTTPRequestOperationManager.h"
//#import "Videos.h"
#import "UIImageView+WebCache.h"
#import "VideosdetailViewController.h"
@interface VideosViewController ()
@property(nonatomic,retain)NSMutableArray *arr;
@end

@implementation VideosViewController
- (void)dealloc
{
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupRefresh];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

-(void)setupRefresh
{
    UIRefreshControl *control=[[[UIRefreshControl alloc]init]autorelease];
    control.tintColor=[UIColor redColor];
    control.attributedTitle=[[[NSAttributedString alloc]initWithString:@"刷新中"]autorelease];
    [control addTarget:self action:@selector(refreshStateChang:) forControlEvents:UIControlEventValueChanged];
    [self.tableView addSubview:control];
    [control beginRefreshing];
    [self  refreshStateChang:control];
    
    
    
    
}

-(void)refreshStateChang:(UIRefreshControl *)control
{
    //AFHTTPRequestOperationManager *mgr=[AFHTTPRequestOperationManager manager];
    //[mgr GET:@"http://223.6.252.214/weibofun/weibo_list.php?apiver=10500&category=weibo_videos&page=0&page_size=30&max_timestamp=-1&vip=1&platform=iphone&appver=1.6&udid=AF8269F5-E81A-4E7E-ADA6-BB3E934A97ED" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        //NSArray *array1=responseObject[@"items"];
        //self.arr=[NSMutableArray array];
        
        //for (NSDictionary *dic in array1) {
            
            //Videos *vid=[[Videos alloc]init];
            //[vid setValuesForKeysWithDictionary:dic];
            //[self.arr addObject:vid];
            //[self.tableView reloadData];
            //[control endRefreshing];
            
           
        }
        
       
        
        
        
        
    //} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
       // NSLog(@"Erro = %@", error);
        //[control endRefreshing];
        
    //}];
//}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return [_arr count];
  
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}




//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//   
//   static NSString *reuseIndentifier=@"reuse";
//    VideoTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:reuseIndentifier];
//  if (nil==cell) {
//        cell = [[VideoTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIndentifier];
//    
//    }
//
//    Videos *vid=[[Videos alloc]init];
//    vid=self.arr[indexPath.row];
//    cell.video=vid;
//    return cell;
//}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    VideosdetailViewController *detail=[[[VideosdetailViewController alloc]init]autorelease];
        detail.hidesBottomBarWhenPushed=YES;  //push 进去是隐藏 tabbaritem
 [self.navigationController pushViewController:detail animated:YES];
    
    //detail.vid=self.arr[indexPath.row];
  
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
